import { IsDiyReg } from '@/rules/is-diyReg.rule'
import { ValidationPipe } from '@nestjs/common'
import {
  IsNotEmpty,
  IsEmail,
  Length,
  isNotEmpty,
  validate,
  Validate,
  IsNumberString,
  Min,
  Max,
  length,
} from 'class-validator'
import { min } from 'lodash'
import { ISConfirmed } from 'src/rules/is-confirmed.rule'
import { IsNotExistsRule } from 'src/rules/is-not-exists.rule'

export class registerUser {
  @IsNotEmpty({ message: '用户名不能为空' })
  @IsDiyReg(/^\w{4,15}$/, { message: '用户名只能为4~15的英文或数字' })
  @IsNotExistsRule('User', { message: '用户名已经存在' })
  user_name: string

  @IsDiyReg(/[\u4e00-\u9fa5_a-zA-Z0-9_]{2,15}/, { message: '昵称只能为2~15的中文或数字,字母' })
  @IsNotEmpty({ message: '昵称不能为空' })
  nickName: string

  @IsNotEmpty({ message: '验证码不能为空' })
  @IsNumberString({}, { message: '验证码类型错误' })
  @Length(5, 5, { message: '验证码格式必须为5位数字' })
  code: string

  @IsNotEmpty({ message: '密码不能为空' })
  @Validate(ISConfirmed, { message: '两次输入的密码不一致' })
  password: string

  @IsNotEmpty({ message: '重复密码不能为空' })
  confirmed_password: string

  @IsEmail({}, { message: '邮箱格式不正确或不存在' })
  @IsNotExistsRule('User', { message: '邮箱已经存在' })
  email: string
}

export class Login {
  @IsNotEmpty({ message: '用户名不能为空' })
  @Length(4, 15, { message: '用户名4~15' })
  user_name: string

  @IsNotEmpty({ message: '密码不能为空' })
  password: string
}
